#define _DEFAULT_SOURCE 1
#include "pool.h"
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

void acc_a(void *argv)
{
    int *num = argv;
    pthread_mutex_lock(&lock);
    (*num)++;
    pthread_mutex_unlock(&lock);
}

int main(int argc, char const *argv[])
{
    int a = 0;
    pool_init(10);

    for (size_t i = 0; i < 20000; i++)
    {
        pool_registerTask(acc_a, &a);
    }

    while (a < 20000) {
        usleep(100000);
    }
    printf("%d\n", a);

    pool_deinit();

    return 0;
}
